﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

//自定义命名空间
using DreamCube.Foundation.Basic.Objects.Log;
using DreamCube.Apps.Common.WinForm.Controls;

namespace PicServer.UI
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.Run(new MainForm());
        }

        /// <summary>
        /// 当前程序域未处理异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                if(e.IsTerminating)
                {
                    MessageBoxHelper.Information(null,"您好，程序发生严重异常，必须关闭！");
                }
                LoggerManager.Logger.MakeLogAsync("程序发生未处理异常:" + e.ExceptionObject.ToString());
            }
            catch (Exception)
            { }
        }

        /// <summary>
        /// 线程异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            try
            {
                LoggerManager.Logger.MakeLogAsync(e.Exception);
            }
            catch (Exception)
            { }
        }
    }
}
